package com.xinghai.admin.controller;

import com.xinghai.admin.service.ISysConfigService;
import com.xinghai.common.constant.CacheKeyConstants;
import com.xinghai.common.core.domain.AjaxResult;
import com.xinghai.admin.entity.XingHaiCommonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinghai.common.config.XingHaiConfig;
import com.xinghai.common.utils.StringUtils;

/**
 * 首页
 *
 * @author xinghai
 */
@RestController
public class SysIndexController
{
    /** 系统基础配置 */
    @Autowired
    private XingHaiConfig xinghaiConfig;
    /** 系统基础配置 */
    @Autowired
    private ISysConfigService configService;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index()
    {
        return StringUtils.format("欢迎使用{}，当前版本：v{}，请通过前端地址访问。", xinghaiConfig.getName(), xinghaiConfig.getVersion());
    }

    /**
     * 获取系统配置
     */
    @RequestMapping("/getCommonConfig")
    public AjaxResult getCommonConfig()
    {
        XingHaiCommonConfig config = new XingHaiCommonConfig();
        String title = configService.selectConfigByKey(CacheKeyConstants.ADMIN_TITLE_KEY);
        config.setTitle(StringUtils.isNotEmpty(title)?title:xinghaiConfig.getName());
        String version = xinghaiConfig.getVersion();
        config.setVersion(version);
        return AjaxResult.success(config);
    }
}
